<?php

namespace Api\Model;

use Think\Model;

class UserCategoryModel extends Model {

    /**
     * @name 保存用户喜好
     */
    public function savaCategory($userid, $category = array ()) {
        $this->where("`user_id`={$userid}")->delete();
        foreach ($category as $key => $val) {
            $data = array ('user_id' => $userid, 'category_id' => $val);
            $this->add($data);
        }
    }

    /**
     * @name 获取用户喜好
     */
    public function getUserCategory($userid) {
        $result = $this->where("`user_id`={$userid}")->getField('category_id', true);
        return array ('user_category' => $result);
    }

}